﻿using _14Net8AspNetCore_Authorization.Context;
using _14Net8AspNetCore_Authorization.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace _14Net8AspNetCore_Authorization.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UsePermissionController : ControllerBase
    {
        private readonly AuthorizationDbContext _DbContext;

        public UsePermissionController(AuthorizationDbContext dbContext)
        {
            _DbContext = dbContext;
        }


        /// <summary>
        /// 添加用户权限控制
        /// </summary>
        /// <param name="permission"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> AddPermission(UsePermission permission)
        {
            _DbContext.UsePermissions.Add(permission);
            _DbContext.SaveChanges();
            return Ok("添加成功");
        }

        /// <summary>
        /// 添加用户权限控制
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> Permission()
        {
            List<UsePermission> usePermissions = _DbContext.UsePermissions.ToList();
            return Ok(usePermissions);
        }

    }
}
